﻿
//是否允许查看预算详细信息
var bIsCanOpenCostInfo = false;

var ExpenseGUID = "";

function PageLoad(sBusinessGUID, sDomainXML)
{
    //设置全局变量值
    ExpenseGUID = sBusinessGUID;

    //生成[报销明细列表、科目分摊列表、冲账明细列表]
    //填充表单(解决嵌套页面的打印问题)
    var sPath = "/PubProject/workflow/cbgl/ExpenseApprove_HTML_Table.aspx?oid=" + sBusinessGUID + "&mode=3&type=" + escape("日常报销审批单") + "&action=ajax";
    var html = openXMLHTTP(sPath, "");
    document.getElementById("printTD").innerHTML = html;

    //设置查看预算详细信息的权限
    setCostInfoOpenPrivilege(sDomainXML);
}


//功能：设置查看预算详细信息的权限
//说明：//有权限的条件是：当前节点处理类型=“审批”  and  (当前节点的状态=“在办” or当前节点的状态=“待办”)        说明：代码里写时，“审批”、“在办”、“待办”分别对应的是1、2、1。
function setCostInfoOpenPrivilege(sDomainXML)
{
    var xmlDom = new ActiveXObject("Microsoft.XMLDOM");
    if (sDomainXML && sDomainXML.length > 0)
    {
        xmlDom.async = false;
        xmlDom.loadXML(sDomainXML);

        if (xmlDom.parseError.errorCode != 0)
        {
            xmlDom = null;
            return;
        }
    }
    else
    {
        xmlDom = null;
        return;
    }
    
    //取当前节点的处理类型；
    var sHandleType = xmlDom.documentElement.getAttribute("HandleType");
    //取当前节点的状态；
    var sNodeStatus = xmlDom.documentElement.getAttribute("NodeStatus");

    if (sHandleType == "[审批]" && (sNodeStatus == "2" || sNodeStatus == "1"))
    {
        bIsCanOpenCostInfo = true;
    }
    else
    {
        bIsCanOpenCostInfo = false;
    }
}

//功能：发起审批时校验			
function InitValidate()
{
    //发起审批时校验。调用日常报销发起审批前校验函数	
    if (checkBeforeApprove(ExpenseGUID, true, "日常报销"))
    {
        return true;
    }
    else
    {
        return false;
    }
}


//功能	  ：通过XMLHTTP通道调用ASPX页面 －－－xiarx modi at 2005.9.9
//调用参数：sFile － 调用页面：页面地址面可跟参数
//调用参数：sType － 业务类型：
//调用参数：sSend － 可选参数，如果不为空，则需要用POST调用，并发送该字符串
//返回    ：“-1”－ 取数失败
function openXMLHTTP(sFile, sType, sSend)
{
    var rdNum = Math.random();
    var oHTTP = new ActiveXObject("Msxml2.XMLHTTP");

    var strTmp = "";
    if (sFile.indexOf("?") == -1)
    {
        strTmp = "?";
    }
    else
    {
        strTmp = "&";
    }

    var sUrl = sFile + strTmp + "ywtype=" + escape(sType) + "&rdnum=" + rdNum;

    if (sSend != "" && sSend != undefined)
    {
        oHTTP.open("POST", sUrl, false);
        oHTTP.send(sSend);
    }
    else
    {
        oHTTP.open("GET", sUrl, false);
        oHTTP.send();
    }

    var bSuccess = handleXMLErr(oHTTP.responseXML);
    if (bSuccess)
    {
        return oHTTP.responseText;
    }
    else
    {
        return "";
    }
}

function handleXMLErr(xml, bContinue)
{
    if (bContinue == null) bContinue = false;
    if (xml.parseError.errorCode != 0)
    {
        alert("操作失败，请关闭重试！");
        if (!bContinue)
        {
            return 0;
        }
        else
        {
            return 2;
        }
    }
    return 1;
}


//打开窗口函数
function openMyWin2(sPath, sName)
{
    var iX = 600;
    var iY = 400;
    if (!sName) sName = ""; var iL, iT;
    iL = (window.screen.width - iX) / 2;
    iT = (window.screen.height - iY - 80) / 2;
    if (iL < 0) iL = 0;
    if (iT < 0) iT = 0;
    try
				{ var x = window.open(sPath, sName, "left=" + iL + ",top=" + iT + ",width=" + iX + ",height=" + iY + ",status=1,resizable=1"); x.focus(); }
    catch (e) { }
}

//查看科目使用情况
function GetCosting(obj)
{
    if (!bIsCanOpenCostInfo)
    {
        alert("当前审批状态不可查看预算详细信息！");
        return;
    }

    var strGUID = obj.parentNode.firstChild.innerHTML;

    var sName = "科目明细";
    var sUrl = "/PubProject/workflow/cbgl/ExpenseApprove_CostInfo.aspx?oid=" + strGUID + "&mode=3";

    openMyWin2(sUrl, sName);
}